package edu.ycxy.poetry.controller;

import edu.ycxy.poetry.entity.DjType;
import edu.ycxy.poetry.service.IDjTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @Author @xin
 * @createDate 2022/3/14
 * @Description
 */
@RestController
@RequestMapping("/type")
@Slf4j
public class DjTypeController {

    @Autowired
    private IDjTypeService djTypeService;

    @RequestMapping("/mainType")
    public List<DjType> selectType(){
        log.debug("获取到的主类型为:"+djTypeService.selectType());
        return djTypeService.selectType();
    }

    //根据古文典籍的主类型所得的id查询古文典籍的具体类型
    @RequestMapping("/mainType/allType")
    public HashMap<String,List> selectByTypeId(){
        HashMap<String,List> map = new HashMap<>();
        List<DjType> types = djTypeService.selectType();
        for (DjType type : types) {
            log.debug("古籍类型名:->"+type.getName()+"=>古籍的id->"+type.getId());
            map.put(type.getName(),djTypeService.selectByTypeId(type.getId()));
        }
        log.debug("获取的map内容"+map);
        return map;
    }
}
